#include "position.h"

Position::Position()
{

}

void Position::decodeNMEA(QByteArray GPSBuffer)
{
    // $GPRMC,080640.683,A,3038.3765,N,11426.3436,E,0.09,155.52,280820,,,A*6B
    if(GPSBuffer.contains("$GPRMC"))
    {
        bool hasLatitude = false;
        bool hasLongitude = false;

        QList<QByteArray> gpsByteArrays = GPSBuffer.split(',');

        QString tt = QString(gpsByteArrays.value(9)).insert(4, "-20").insert(2, '-') + " " + QString(gpsByteArrays.value(1)).insert(4, ':').insert(2, ':');
        datetime   = QDateTime::fromString(tt, "dd-MM-yyyy hh:mm:ss.zzz").addSecs( 8 * 60 * 60);
        state      = QString(gpsByteArrays.value(2)) == "A";
        latitude   = gpsByteArrays.value(3).toDouble(&hasLatitude);
        ns         = QString(gpsByteArrays.value(4));
        longitude  = gpsByteArrays.value(5).toDouble(&hasLongitude);
        ew         = QString(gpsByteArrays.value(6));
        speed      = gpsByteArrays.value(7).toDouble();
        course     = gpsByteArrays.value(8).toDouble();
    }
}
